<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div class="demo1"></div>
    <div class="demo2"></div>
    <script type="text/template" id="demo1">
        <h3><%=name%></h3>
        <p><%=age%></p>
    </script>
    <script type="text/template" id="demo2">
        <% for(var i = 0; i < arr.length; i++){ %>
            <%= i %> <%= arr[i]['name'] %> <%= arr[i]['age'] %>
        <% } %>
    </script>
    <script src="artTemplate/template-native.js"></script>
    <script>
        //对象的渲染
        var data1 = { name: '小明', age: 24 };
        var tpl = template('demo1', data1);
        document.querySelector('.demo1').innerHTML = tpl;
    </script>
    <script>
        /*
        注意事项: 
            1、template方法的第二个参数是普通对象，一定不要是数组
            2、如果是数组怎么办? ---> 包一层
        */
        //数组的渲染
        var data2 = {
            arr: [{ name: '小明', age: 24 }, { name: '小王', age: 24 }, { name: '小李', age: 24 }, { name: '小马', age: 24 }]
        }
        var tpl = template('demo2', data2);
        document.querySelector('.demo2').innerHTML = tpl;
    </script>
</body>

</html>